home *** CD-ROM | disk | FTP | other *** search
- Path: news1.sunbelt.net!dial-3
- From: dking@SunBelt.Net
- Newsgroups: comp.lang.c
- Subject: Reading directory into array of some kind.
- Date: 10 Feb 1996 19:35:55 GMT
- Organization: SunBelt.Net INTERNET Access
- Message-ID: <4fis2r$tc7@news1.sunbelt.net>
- NNTP-Posting-Host: dial-3.r1.gaagst.sunbelt.net
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- The following bit of code uses the findfirst/findnext to read all the
- filesname out of the current directory. I had HOPED to be able to put the file
- names into some sort of array but couldn't find a way to make it work.
-
- I have spent the last several days just trying to get an array of file names
- without success.. (I didn't save the code of the unsuccessful attempts) I
- tried moving the ffblk.name into another structure but it wouldn't work. You
- can't use arrays as lvalues and assign them the name, pointer arrays only
- pointed to the last filename read in...
-
- several assumptions:
-
- A). Yes, I'm new at this..
-
- B). No the online Borland help files were NOT helpfull... (Turbo C++ for
- Windows ver 3.1)
-
- C). The Tutorials I have were also not helpfull.. they usually had the data
- pre-defined or typed in, so examples for pulling a string from a structure to
- an array or another structure were not given..
-
- D). None of my other documentation would seem to have any answers.. at least
- none that make sense or explain fully what needed to be done.
-
- Any help on this would be greatly appreciated.
-
- Thanks,
-
- Daryl
-
-
- #include <stdio.h>
- #include <dos.h>
- int main()
- {
-
- struct find_t ffblk;
- int done;
-
- printf("Directory listing \n");
-
- done = _dos_findfirst("*.*",255,&ffblk); //reads all files from directory
- while (!done)
- {
- printf(" %s\n", ffblk.name); //print file names
- done = _dos_findnext(&ffblk);
- }
-
- return 0;
- }
-